# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Ray Rashif <schiv@archlinux.org>
# Contributor: speps <speps at aur dot archlinux dot org>

pkgbase=lilv
pkgname=(lilv lilv-docs)
pkgver=0.24.20
pkgrel=2
pkgdesc="A C library interface to the LV2 plug-in standard"
arch=(loong64 x86_64)
url="https://drobilla.net/software/lilv.html"
license=(ISC)
makedepends=(doxygen libsndfile lv2 meson python python-sphinx python-sphinx-lv2-theme serd sord sratom swig)
source=(https://download.drobilla.net/$pkgname-$pkgver.tar.xz{,.sig})
sha512sums=('68963b66fd6e577280867fcd5a601fd2cf539a10fcf0b667c22165cc7e42206fd6a20d56dbe97b587fb68f798d4db3b2351b87b1243c665c3a2b1bb82cbbf9a3'
            'SKIP')
b2sums=('50b2044a7fb62cfcbea6dc68cd0d26503780f30a5a04e2ceafca9e02b2369965d7d27b8d08bbfa136930a3b18a3e0eb6cf4c326d3c2d46218badb4a8ec6e1e01'
        'SKIP')
validpgpkeys=('907D226E7E13FA337F014A083672782A9BF368F3') # David Robillard <d@drobilla.net>

_pick() {
  local p="$1" f d; shift
  for f; do
    d="$srcdir/$p/${f#$pkgdir/}"
    mkdir -p "$(dirname "$d")"
    mv "$f" "$d"
    rmdir -p --ignore-fail-on-non-empty "$(dirname "$f")"
  done
}

build() {
  arch-meson $pkgname-$pkgver build
  meson compile -C build
}

check() {
  meson test -C build
}

package_lilv() {
  depends=(glibc libserd-0.so libsord-0.so libsratom-0.so lv2)
  optdepends=(
    'libsndfile: for lv2apply'
    'lilv-docs: for documentation'
    'python-numpy: for Python bindings'
  )
  provides=(liblilv-0.so)

  meson install -C build --destdir "$pkgdir"
  (
    cd "$pkgdir"
    _pick $pkgname-docs usr/share/doc
  )
  install -vDm 644 $pkgname-$pkgver/COPYING -t "$pkgdir/usr/share/licenses/$pkgname/"
  install -vDm 644 $pkgname-$pkgver/{NEWS,README.md} -t "$pkgdir/usr/share/doc/$pkgname/"
  # install bash completion to correct directory and remove /etc
  install -vDm 644 "$pkgdir/etc/bash_completion.d/$pkgname" -t "$pkgdir/usr/share/bash-completion/completions/"
  rm -frv "$pkgdir/etc"
}

package_lilv-docs() {
  pkgdesc+=" - documentation"

  mv -v $pkgname/* "$pkgdir"
  mv -v "$pkgdir/usr/share/doc/$pkgbase"{-0,}
  find "$pkgdir" -type f -iname "*.buildinfo" -delete
}
